package com.incar.chuxing.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.incar.chuxing.R;

public class SystemToastUtils {
    private static Toast mToast;

    private SystemToastUtils() {

    }


    public static Toast makeText(Context context, String msg, int duration) {
        if (msg == null) {
            msg = "";
        }

        if (mToast == null) {
            mToast = new Toast(context);
        }

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        //自定义布局
        View view = inflater.inflate(R.layout.layout_toast, null);
        //自定义toast文本
        ((TextView) view.findViewById(R.id.toast_title)).setText(msg);

        //设置toast居中显示
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.setDuration(duration);
        mToast.setView(view);
        return mToast;
    }

    /**
     * 自定义居中显示toast
     */
    public void show() {
        if (mToast != null) {
            mToast.show();
        }
    }
}
